﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EasyStep.Business.Interfaces;
using EasyStep.Data.Entities;
using System.Web.Security;

namespace EasyStep.Business.Managers
{
    public class TestUserManager : ITestUserManager
    {
        public TestUser Current()
        {
            var data=ConvertTo(Membership.GetUser());
            return data;
        }

        

        public bool Authorize(TestProject test)
        {
            return Current().Id == test.UserId; 
        }

        public TestUser Get(Guid id)
        {
            var data = ConvertTo(Membership.GetUser(id,false));
            return data;
        }
        public TestUser Get(string name)
        {
            var data = ConvertTo(Membership.GetUser(name, false));
            return data;
        }
        public TestUser Create(TestUser data)
        {
            throw new NotImplementedException();
        }

        public TestUser Update(TestUser data)
        {
            throw new NotImplementedException();
        }

        public TestUser Delete(TestUser data)
        {
            throw new NotImplementedException();
        }


        public TestUser ConvertTo(MembershipUser user)
        {
            return user==null? null:new TestUser(){
                Id=(Guid)user.ProviderUserKey,
                Name=user.UserName,
                Created=user.CreationDate,
                Updated=user.LastActivityDate 
            };
        }
    }
}
